<?php
/*
 * @Author: your name
 * @Date: 2021-11-02 19:06:50
 * @LastEditTime: 2022-03-01 13:34:28
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /nlog/app/Models/admin_model/Admin.php
 */

namespace App\Models\crm_model;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;

class CrmDivision extends Model
{
    use HasFactory;
    static string $tableName = 'crm_division';
    
  
    // public static function areaListSelListWeb(){
        // return DB::select(" SELECT * FROM  `area` WHERE `delete_time` is null AND `status` = 1 ORDER BY `sort` DESC,`id` DESC  ");
    // }
   
    public static function divisionList($id){
         return DB::select(" SELECT * FROM ".self::$tableName." WHERE (`id` = ".$id." OR `pid` = ".$id." ) AND `delete_time` is null   ");
    }

    public static function divisionAll($whereStr = ''){
        return DB::select(' SELECT `crm_division`.*,`crm_role`.`name` as `role_name`  FROM '.self::$tableName.' INNER JOIN `crm_role` ON `crm_role`.`id` = `crm_division`.`crm_role_id` WHERE `crm_division`.`delete_time` is null '.$whereStr.' ORDER BY `sort` DESC ,  `id` DESC ');
    }
    
    
   
}
